package com.chen.blue.converter.business;

import com.chen.blue.domain.dto.business.CompetitionDto;
import com.chen.blue.domain.dto.business.update.CompetitionEdit;
import com.chen.blue.domain.model.business.CompetitionModel;
import com.chen.blue.domain.vo.business.CompetitionVo;
import org.springframework.cglib.beans.BeanCopier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created By CLT On 2024/6/20.
 */
@SuppressWarnings("all")
public abstract class CompetitionConverter {

    private static final BeanCopier modelToVo = BeanCopier.create(CompetitionModel.class, CompetitionVo.class, false);
    private static final BeanCopier dtoToModel = BeanCopier.create(CompetitionDto.class, CompetitionModel.class, false);
    private static final BeanCopier dtoEditToModel = BeanCopier.create(CompetitionEdit.class, CompetitionModel.class, false);

    /**
     * model->vo
     *
     * @param model
     * @return
     */
    public static CompetitionVo modelToVo(CompetitionModel model) {
        if (Objects.isNull(model)) {
            return null;
        }
        CompetitionVo contestApplyActiveVo = new CompetitionVo();
        modelToVo.copy(model, contestApplyActiveVo, null);
        return contestApplyActiveVo;
    }

    /**
     * model->volist
     *
     * @param modelList
     * @return
     */
    public static List<CompetitionVo> modelToVoList(List<CompetitionModel> modelList) {
        if (modelList.size() == 0) {
            return null;
        }

        List<CompetitionVo> contestApplyActiveVoList = new ArrayList<>();
        for (CompetitionModel contestApplyActiveModel : modelList) {
            contestApplyActiveVoList.add(modelToVo(contestApplyActiveModel));
        }

        return contestApplyActiveVoList;

    }

    /**
     * dto->model
     *
     * @param postDto
     * @return
     */
    public static CompetitionModel dtoToModel(CompetitionDto contestApplyActiveDto) {

        if (Objects.isNull(contestApplyActiveDto)) {
            return null;
        }

        CompetitionModel contestApplyActiveModel = new CompetitionModel();
        dtoToModel.copy(contestApplyActiveDto, contestApplyActiveModel, null);
        return contestApplyActiveModel;

    }

    /**
     * editDto->model
     *
     * @param postDtoEdit
     * @return
     */
    public static CompetitionModel dtoEditToModel(CompetitionEdit contestApplyActiveDtoEdit) {

        if (Objects.isNull(contestApplyActiveDtoEdit)) {
            return null;
        }

        CompetitionModel contestApplyActiveModel = new CompetitionModel();
        dtoEditToModel.copy(contestApplyActiveDtoEdit, contestApplyActiveModel, null);
        return contestApplyActiveModel;

    }

}
